package Ioperation;

import book.BookList;

import java.util.Scanner;

public class Borrowoperation implements Ioperation{
    @Override
    public void work(BookList books) {
        int ret = books.getBooksSize();
        if(ret == 0){
            System.out.println("书架上没有书!");
            return;
        }
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入要借阅的书名:");
        String name = scanner.nextLine();

        //查找
        for (int i = 0; i < ret; i++) {
            if(name.equals(books.getBooks(i).getName())){
                //判断书的状态是否被 借走
                if(books.getBooks(i).isState()) {
                    System.out.println("这本书已经被借走了!");
                    return;
                }else {
                    //没被借走，就修改状态，
                    books.getBooks(i).setState(true);
                    System.out.println("借阅成功!");
                    return;
                }
            }
        }
        System.out.println("没有这本书!");
    }
}
